<!--
 * @Author: luosi 1297957337@qq.com
 * @Date: 2024-11-20 15:21:45
 * @LastEditors: huang liang miao 1127255342@qq.com
 * @LastEditTime: 2024-12-16 10:55:57
 * @FilePath: \dcy-webd:\webCode\dcyCode\scientific_research_manager_web\src\views\achievementReward\myResearchPoint\index.vue
 * @Description: 我的科研分列表
-->
 
<script setup lang="ts">
import formateDate from '@/utils/formateDate'
import { achvTypeList } from '@/utils/typeList'
import { myResearchRewardListRep } from "@/api/assessment/index"

const router = useRouter()
const dataList = ref()
const total = ref(0)
const queryParams = ref<any>({
  page: 1,
  size: 20
})
const columns = ref<any>([
  {
    title: '序号',
    width: 48,
    formatter: (_row: any, _column: any, _cellValue: any, index: number) => {
      return index + 1
    }
  },
  {
    title: '名称',
    minWidth: 320,
    dataIndex: 'name',
  },
  {
    title: '考核年度',
    minWidth: 100,
    dataIndex: 'year',
    formatter: (record) => {
      return `${record.year}年度`
    },
  },
  {
    title: '起止时间',
    minWidth: 200,
    dataIndex: 'startTime',
    formatter: (record) => {
      return `${formateDate(record.startTime).format('YYYY-MM-DD')} ~ ${formateDate(record.endTime).format('YYYY-MM-DD')}`
    },
  },
  {
    title: '总科研分',
    minWidth: 100,
    dataIndex: 'totalScore',
  },
  {
    title: '工作量详情',
    minWidth: 360,
    dataIndex: 'achvInfoResultVOS',
    slotName: 'achvInfoResultVOS',
  },
  {
    title: '考核状态',
    minWidth: 100,
    dataIndex: 'status',
    formatter: (record) => {
      const statusType = {
        1: '未开始',
        2: '考核中',
        3: '考核结束',
      }
      return statusType[record.status]
    },
  },
  {
    title: '操作',
    minWidth: 80,
    dataIndex: 'default',
    slotName: 'default',
  }
])

// 查询列表
const { run: myResearchRewardList, loading } = useRequest(myResearchRewardListRep, {
  // false 为自动执行
  manual: true,
  // 请求成功
  onSuccess: (data: any) => {
    dataList.value = data.content || []
    total.value = data.totalElements
  },
})
onSearch()

// 过滤查询
function onSearch() {
  myResearchRewardList(queryParams.value)
}
function toView(record) {
  router.push(`./myResearchPoint/details?year=${record.year}`)
}
// 分页
function pagetionSerach(params){
  queryParams.value = {
    ...queryParams.value,
    ...params,
  }
  onSearch()
}
</script>

<template>
  <div class="app-container">
  <TableForm ref="tableRef" :auto-height="true" :data="dataList" :columns="columns"
    :tableLoading="loading" :total-count="total" :showPagination="true" :showToolBar="false"
    @refresh="pagetionSerach">
    <template #achvInfoResultVOS="{ record }">
      <div v-if="record?.achvInfoResultVOS?.length">
        <div v-for="item in record.achvInfoResultVOS" class="other-tr">
          <span>{{ achvTypeList[item.achvType] }}：</span>
          <span v-for="(v, i) in item.resultDetailVOS">
            {{ v.quanIndicators }}{{ v.number }}{{ v.unit }}{{ v.researchScore }}分
            <span v-if="i !== item.resultDetailVOS.length - 1">、</span>
          </span>
        </div>
      </div>
      <div v-else>-</div>
    </template>
    <template #default="{ record }">
      <el-button link type="primary" @click="toView(record)">查看 </el-button>
    </template>
  </TableForm>
</div>
</template>

<style scoped lang="scss">
.app-container {
  :deep(.cell:has(.other-tr)){
    padding: 0 !important;
    .other-tr{
      @apply: px-[8px] py-[14px] border-b border-color-[#BEDAFF];
      &:last-child{
        @apply: border-none;
      }
    }
  }
}
</style>